package com.grandbroad.eim.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.MenuItem;
import android.view.View;

import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * 所有acitivty的基类
 * Created by even alone on 2018/6/2.
 */

public abstract class BaseActivity extends LibActivity
{
    //开启event在application里处理
    private Unbinder unbinder;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(setlayout());
        unbinder = ButterKnife.bind(this);
        initdata();
        initview();


    }


    /**
     * 视图初始化入口
     */
    protected abstract void initview();

    /**
     * 数据初始化入口
     */
    protected abstract void initdata();
    /**
     * 设置布局
     * @return
     */
    protected abstract int setlayout();

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unbinder.unbind();
    }
    /**
     * 重写返回按钮
     */
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId())
        {
            case android.R.id.home:
                finish();
                break;
            case android.R.id.title:
                finish();
                break;
        }
        return true;
    }

    /**
     * 设置返回按钮
     * @param view
     */
    public void setBackBtn(View view)
    {
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }


}